package com.youxin.foundation.utils.thread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 自定义基类ThreadFactory
 * @author yingde.cao
 *
 */
public class BaseThreadFactory implements ThreadFactory {

	private final AtomicInteger mThreadNum = new AtomicInteger(1);

	private  String name;
	
	private final boolean daemo;
	
	public BaseThreadFactory(){
		this("Global");
	}
	
	public BaseThreadFactory(String name)
	{
		this(name, false);
	}
	
	public BaseThreadFactory(String name,boolean daemo)
	{
		this.name=name;
		this.daemo = daemo;
	}
	
	@Override
	public Thread newThread(Runnable r) {
		String threadName = name+"-" + mThreadNum.getAndIncrement();
		Thread ret = new Thread(r,threadName);
        ret.setDaemon(daemo);
        return ret;
	}
	
}
